--
-- Author: yawei.zhu
-- Date: 2018-10-10 11:39:47
--
-- BossTeamRankMoreRender
--
local AvatarFactotry = require("app.public.avatar.AvatarFactory")
local HeadRender = require("app.widget.renders.HeadRender")

local ClassRef = app.mvc.createRenderClass(...)

--data =
function ClassRef.createWithData(data, node)
    local sprite = ClassRef.extend(node or cc.CSLoader:createNode(Res.BossTeamMoreRankUI))
    if node == nil then
        ccui.Helper:doLayout(sprite)
    end
    sprite:init(data)
    return sprite
end
function ClassRef.create(node)
    return ClassRef.createWithData(nil, node)
end

--
function ClassRef:init(data)
    self.super.init(self, data)

    self:setContentSize(self._ui.Panel:getContentSize())

    self:refresh()
end

function ClassRef:refresh()
    if not self._data then return end

    local members = self._data
    local panelTeam = self._ui.Panel_team

    for i = 1, 5 do
        local player = panelTeam:getChildByName("player0"..i)
        if members[i] then
            local baseInfo = members[i].userBaseInfo
            player:findChild("Panel/Panel_withData"):setVisible(true)

            local h = HeadRender.create(player:findChild("Panel/Panel_withData/head"), 3)
            h:setData( cloneWithoutMeta(baseInfo) )

            player:findChild("Panel/Panel_withData/name"):setString(L(baseInfo.name))
            if not members[i].isLeader then
                player:findChild("Panel/Panel_withData/name"):setTextColor(cc.c3b(108,158,239))
            else
                player:findChild("Panel/Panel_withData/name"):setTextColor(cc.c3b(255,255,255))
            end
            player:findChild("Panel/Panel_withData/lv_tlt"):setString(baseInfo.lv..L("lua_code_text_262"))
            
            local ary = string.split( baseInfo.specialistID, "0" )
            local str = L("class_" .. ary[1] .. "_" .. ary[2] ) .. L("class_"..baseInfo.classID)
            player:findChild("Panel/Panel_withData/class"):setString(str)

            player:findChild("Panel/Panel_withData/icon_leader"):setVisible(members[i].isLeader)
            player:findChild("Panel/Panel_withData/Image_Forbidden"):setVisible(false)                    
            player:findChild("Panel/Panel_withData/partner"):setVisible(false)

        else
            player:findChild("Panel/Panel_withData"):setVisible(false)
        end

    end
end

function ClassRef:onBtnClick(cb)
    self._onClick = cb
end

return ClassRef
